/**
 * @Title: model.js
 * @Description: model
 * @author: Fanchao
 * @date: 2020/8/9 2:16 下午
 * @version V1.0
 */

import { pathToRegexp } from 'path-to-regexp';
import { message } from 'antd';
import { getNoticeModelList } from 'api/index';

export default {
    namespace: 'home',
    state: {
        dataSource: [],
    },
    reducers: {
        setDataSource(state, { payload: dataSource }) {
            return {
                ...state,
                dataSource,
            };
        },
    },
    effects: {
        /**
         * @desc 获取任务提醒列表
         * @param payload
         * @param call
         * @param put
         * @param select
         * @returns {Generator<*, void, *>}
         */* getDataSource({ payload }, { call, put, select }) {
            const result = yield call(getNoticeModelList, payload);
            if (result.status === 'success') {
                const dataSource = result.result;
                yield put({
                    type: 'setDataSource',
                    payload: dataSource,
                });
            } else {
                message.error(result.message);
            }
        },
    },
    subscriptions: {
        setup({ dispatch, history }) {
            return history.listen(({ pathname }) => {
                if (pathToRegexp('/home').exec(pathname)) {
                }
            });
        },
    },
};
